using Mabinogi;

namespace XMLDB3
{
	internal class MabiNovelSelectBoardCommand : BasicCommand
	{
		private long sn_;

		private string author_ = "";

		private Posts posts_;

		public MabiNovelSelectBoardCommand()
			: base(NETWORKMSG.NET_DB_MABINOVEL_NOVEL_GET_CHANGE_POSTS)
		{
		}

		protected override void ReceiveData(Message _message)
		{
			sn_ = (long)_message.ReadU64();
			author_ = _message.ReadString();
		}

		public override bool DoProcess()
		{
			WorkSession.WriteStatus("MabiNovelSelectBoardCommand.DoProcess() : 함수에 진입하였습니다");
			posts_ = QueryManager.MabiNovelBoard.GetChangePosts(sn_);
			if (posts_ != null)
			{
				WorkSession.WriteStatus("MabiNovelSelectBoardCommand.DoProcess() : 게시물을 성공적으로 읽었습니다.");
			}
			else
			{
				WorkSession.WriteStatus("MabiNovelSelectBoardCommand.DoProcess() : 게시물을 읽는데 실패하였습니다.");
			}
			return posts_ != null;
		}

		public override Message MakeMessage()
		{
			WorkSession.WriteStatus("MabiNovelSelectBoardCommand.MakeMessage() : 함수에 진입하였습니다");
			Message message = new Message(base.ID, 0uL);
			message.WriteU32(base.QueryID);
			if (posts_ != null)
			{
				posts_.author = author_;
				message.WriteU8(1);
				MabiNovelPostsSerializer.Deserialize(posts_, message);
			}
			else
			{
				message.WriteU8(0);
			}
			return message;
		}
	}
}
